#include "download.h"

const  int download_cap = 1024;
const  int cur_speed = 10;

// 假如网络是10mb左右，模拟实时网速
int NetSpeed()
{
    std::stringstream ss;
    // 1、创建机器随机数对象
    std::random_device rd;
    // // 2、利用机器随机数创建随机生成随机数对象
    // std::mt19937 rand_generator(rd());
    // // 3、生成控制随机数生成范围对象。
    // std::uniform_int_distribution<int> distribution(0, 255);
    return rd() % cur_speed;
}

void download(int total_cap)
{
    int cur_cap = 0;
    while (cur_cap < total_cap)
    {
        cur_cap += NetSpeed();
        if(cur_cap > total_cap) cur_cap = total_cap;
        print_processbar(cur_cap, total_cap);
        usleep(10000);
    }
    return;
}